#include "calc.h"

Calc::Calc(QWidget *parent)
        :QGroupBox(parent)
{
    calcO = new QLineEdit(this);
    calcO->setMaxLength(3);
    calcO->setInputMask(000);

    calcI=new LabeledSlider(this);
    calcI->slider->setTickPosition(QSlider::TicksRight);
    calcI->slider->setRange(0,20);
    calcI->nowValue->setVisible(false);
    QStringList numbers;
    numbers <<"0"<<"1"<<"2"<<"2"<<"4"<<"5"<<"6"<<"7"<<"8"<<"9"<<"10"<<"11"<<"12"<<"13"<<"14"<<"15"<<"16"<<"17"<<"18"<<"19"<<"20";
    calcI->setLabels(numbers);
    more =new QPushButton("+",this);
    minus =new QPushButton("-", this);
    QObject::connect(more, SIGNAL(clicked()),this, SLOT(sum()));
    QObject::connect(minus, SIGNAL(clicked()),this, SLOT(sub()));    
    //LAYOUT
    sliderL = new QHBoxLayout;
    sliderL->addStretch();
    sliderL->addWidget(calcI);
    sliderL->addStretch();
    topL = new QHBoxLayout;
    topL->addWidget(more);
    topL->addWidget(calcO);
    topL->addWidget(minus);
    allL = new QVBoxLayout;
    allL->addLayout(topL);
    allL->addLayout(sliderL);
    setLayout(allL);
}
void Calc::sum()
{
    str=calcO->text();
    int num1=str.toInt();
    int num2=calcI->slider->value();
    int an=num1+num2;
    ans = ans.number(an);
    calcO->setText(ans);
}
void Calc::sub()
{
    str=calcO->text();
    int num1=str.toInt();
    int num2=calcI->slider->value();
    int an=num1-num2;
    ans = ans.number(an);
    calcO->setText(ans);
}
